package com.utooo.controller;

import com.utooo.constant.ResultCodeConstant;
import com.utooo.pojo.dto.common.RestResult;
import com.utooo.service.supplier.SupplierContractAcceptanceService;
import com.utooo.service.supplier.SupplierContractService;
import com.utooo.service.supplier.SupplierOrderInvoiceAssociationService;
import com.utooo.service.supplier.SupplierOrderReconciliationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author CK
 * @Date: 2025−04-24 17:28
 * @Description: SupplierPortalController
 * @Copyright: 南京优通信息科技股份有限公司
 */
@Tag(name = "供应商门户管理")
@RequestMapping("supplier-portal")
@RestController
public class SupplierPortalController {

    @Resource
    private SupplierContractService supplierContractService;

    @Resource
    private SupplierOrderReconciliationService supplierOrderReconciliationService;

    @Resource
    private SupplierContractAcceptanceService supplierContractAcceptanceService;
    @Resource
    private SupplierOrderInvoiceAssociationService supplierOrderInvoiceAssociationService;


    @RequestMapping(value = "/contract/get-contract-No", method = RequestMethod.GET)
    @Operation(summary = "获取采购合同编号")
    public RestResult<String> getContractNo() {
        return new RestResult<>(ResultCodeConstant.CODE_200,
                ResultCodeConstant.CODE_200_MSG,
                supplierContractService.generateContractNo());
    }

    @RequestMapping(value = "/contract/add", method = RequestMethod.GET)
    @Operation(summary = "同步合同申请至采购方")
    public RestResult<Boolean> addContract(@RequestParam String contractId) {
        supplierContractService.addContract(contractId);
        return new RestResult<>(ResultCodeConstant.CODE_200, ResultCodeConstant.CODE_200_MSG);
    }

    @PostMapping("/order/reconciliation/confirm")
    @Operation(summary = "供货方确认订单对账记录")
    public RestResult<String> confirmOrderReconciliation(@RequestParam String id) {
        return supplierOrderReconciliationService.confirmOrderReconciliation(id);
    }

    @PostMapping("/order/reconciliation/revoke")
    @Operation(summary = "供货方退回订单对账记录")
    public RestResult<String> revokeOrderReconciliation(@RequestParam String id) {
        return supplierOrderReconciliationService.revokeOrderReconciliation(id);
    }

    @PostMapping("/contract/acceptance/confirm")
    @Operation(summary = "供货方确认合同验收记录")
    public RestResult<String> confirmContractAcceptance(@RequestParam String id) {
        return supplierContractAcceptanceService.confirm(id);
    }

    @PostMapping("/contract/acceptance/revoke")
    @Operation(summary = "供货方退回合同验收记录")
    public RestResult<String> revokeContractAcceptance(@RequestParam String id) {
        return supplierContractAcceptanceService.revoke(id);
    }

    @PostMapping("/order/invoice/association/confirm")
    @Operation(summary = "供货方确认订单关联发票记录")
    public RestResult<String> confirmOrderInvoiceAssociation(@RequestParam String id) {
        return supplierOrderInvoiceAssociationService.confirmOrderInvoiceAssociation(id);
    }

    @PostMapping("/order/invoice/association/revoke")
    @Operation(summary = "供货方退回订单关联发票记录")
    public RestResult<String> revokeOrderInvoiceAssociation(@RequestParam String id) {
        return supplierOrderInvoiceAssociationService.revokeOrderInvoiceAssociation(id);
    }
}
